//
//  DHLeftBarVC.m
//  DHKuaiYi
//
//  Created by Cedric Zheng on 13/11/2016.
//  Copyright © 2016 30-陈辉华. All rights reserved.
//

#import "DHLeftBarVC.h"
#import "DHLeftBarTopView.h"
#import "DHListModel.h"
#import <Masonry.h>
#import <UIViewController+MMDrawerController.h>

#define SELF_WIDTH self.view.bounds.size.width

@interface DHLeftBarVC () <UITableViewDelegate>

@end

@implementation DHLeftBarVC


#pragma mark - Life Cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self xhhSetupSubviews];
    
    self.tableView.delegate = self;
    
}

#pragma mark - Events

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark – Private Methods
- (void)xhhSetupSubviews {
    
    DHLeftBarTopView *topV = [[DHLeftBarTopView alloc] initWithFrame:CGRectMake(0.0, 0.0, SELF_WIDTH, 100.0)];
    [self.view addSubview:topV];
    
    [self loadDataListWithName:@"LeftBarList.plist"];
    
    //对列表布局做出调整
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topV.mas_bottom);
        make.leading.trailing.bottom.equalTo(self.view);
    }];
}


/**
 根据传入的字符串创建视图控制器

 @param clsName 视图控制器的名的字符串
 @return 创建出来的视图控制器
 */
- (UIViewController *)getControllerWithClassName:(NSString *)clsName {
    UIViewController *vc = [[NSClassFromString(clsName) alloc] init];
    return vc;
}


#pragma mark - UITableViewDelegate

/**
 选中行之后，在centerController推出对应的VC。

 @param tableView tableView
 @param indexPath indexPath
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *modelArr = self.dataList[indexPath.section];
    DHListModel *model = modelArr[indexPath.row];
    NSString *pushVCName = model.pushVCName;
    
    if (pushVCName) {
        [self.mm_drawerController closeDrawerAnimated:YES completion:nil];
        UIViewController *vc = [self getControllerWithClassName:pushVCName];
        UITabBarController *tabBarController = (UITabBarController *)self.mm_drawerController.centerViewController;
        
        [tabBarController.selectedViewController pushViewController:vc animated:YES];
        [tabBarController.selectedViewController hidesBottomBarWhenPushed];
        
    }
}

#pragma mark - <#Datasources#>

#pragma mark – Getters and Setters

@end
